#include "listteacher.h"
#include "editprepod.h"
#include "ui_listteacher.h"
#include "connection.h"

ListTeacher::ListTeacher(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::ListTeacher)
{
    ui->setupUi(this);

    teacher = new QSqlTableModel(this);
    teacher->setTable("\"V_TEACHER\"");
    teacher->select();

    ui->tableTeacher->setModel(teacher);
    setNameFields();
}

ListTeacher::~ListTeacher()
{
    delete ui;
}

void ListTeacher::setNameFields()
{

    teacher->setHeaderData(teacher_lastname, Qt::Horizontal, tr("Last name"));
    teacher->setHeaderData(teacher_firstname, Qt::Horizontal, tr("Fist name"));
    teacher->setHeaderData(teacher_secondname, Qt::Horizontal, tr("Oth"));

    ui->tableTeacher->setSelectionMode(QAbstractItemView::SingleSelection);
    ui->tableTeacher->setSelectionBehavior(QAbstractItemView::SelectRows);
    ui->tableTeacher->setEditTriggers(QAbstractItemView::NoEditTriggers);

    ui->tableTeacher->setColumnHidden(teacher_id, true);
    ui->tableTeacher->setColumnHidden(teacher_fio, true);
    ui->tableTeacher->setColumnHidden(teacher_department_id, true);

    ui->tableTeacher->resizeColumnsToContents();

    QHeaderView *header = ui->tableTeacher->horizontalHeader();
    header->setStretchLastSection(true);
}

void ListTeacher::on_btnClose_clicked()
{

}

void ListTeacher::on_btnEdit_clicked()
{

    EditPrepodForm *uc = new EditPrepodForm(this);
    uc->exec();
}
